package round76;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class A {
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String pass = in.readLine();
        String digits[] = new String[10];
        for (int i = 0; i < 10; i++) {
            digits[i] = in.readLine();
        }

        int j;
        int num = 0;
        int initZeroes = 0;
        for (int i = 0; i < pass.length(); i += 10) {
            for (j = 0; j < 10; j++) {
                if (digits[j].equals(pass.substring(i, i + 10))) {
                    break;
                }
            }
            if (j == 0 && num == 0) {
                initZeroes++;
            }
            num *= 10;
            num += j;
        }
        for (int i = 0; i < initZeroes; i++) {
            System.out.print(0);
        }
        System.out.println(num);
    }
}
